import request from '@/utils/request'

// menu

// 获取菜单树
export function getMenuTree() {
  return request({
    url: '/menus/tree'
  })
}

// 增加菜单
export function createMenu(data) {
  return request({
    url: '/menus',
    method: 'post',
    data
  })
}

// 修改菜单
export function editMenu(id, data) {
  return request({
    url: `/menus/${id}`,
    method: 'put',
    data
  })
}

// 删除菜单
export function deleteMenu(id) {
  return request({
    url: `/menus/${id}`,
    method: 'DELETE'
  })
}

// org

export function getOrgTree (params) {
  return request({
    url: '/org/list',
    params
  })
}

export function updateAreaCode(data) {
  return request({
    url: `/org/${data.id}`,
    method: 'PUT',
    data
  })
}
export function getOrgMap (params) {
  return request({
    url: '/org/map',
    params
  })
}
// 获取组织的所有父级
export function getTreeLink(id) {
  return request({
    url: `/org/${id}/parents`
  })
}
/****** 编辑页面上的接口***/
// 获取组织树
export function getOrgInfo(id) {
  return request({
    url: `/org/${id}`
  })
}

// 组织关联菜单
export function orgRelativeMenu(id, data) {
  return request({
    url: `/org/${id}/menu`,
    method: 'post',
    data
  })
}


/********* role ******/

// 获取角色
export function getRoles (params) {
  return request({
    url: '/roles',
    params
  })
}

// 获取角色
export function getRoleList (params) {
  return request({
    url: '/roles/list',
    params
  })
}

// 获取角色信息
export function getRoleInfo (id) {
  return request({
    url: `/roles/${id}`
  })
}

// 增加角色
export function createRoles (data) {
  return request({
    url: '/roles',
    method: 'post',
    data
  })
}

// 修改角色
export function editRoles (id, data) {
  return request({
    url: `/roles/${id}`,
    method: 'PUT',
    data
  })
}

// 删除角色
export function deleteRoles (id) {
  return request({
    url: `/roles/${id}`,
    method: 'DELETE'
  })
}




// 用户管理

// 获取用户
export function getUsers (params) {
  return request({
    url: '/users',
    params
  })
}

// 获取用户
export function getUserList (params) {
  return request({
    url: '/users/list',
    params
  })
}

// 获取用户
export function getUserMap (params) {
  return request({
    url: '/users/leaderMap',
    params
  })
}

export function getUserInfo (id, params) {
  return request({
    url: `/users/${id}`,
    params
  })
}


// 增加用户
export function createUser (data) {
  return request({
    url: '/users',
    method: 'post',
    data
  })
}

// 修改用户
export function editUser (id, data) {
  return request({
    url: `/users/${id}`,
    method: 'PUT',
    data
  })
}

// 解绑手机号
export function unbindPhone (data) {
  return request({
    url: `/users/unbind/cellphone`,
    method: 'DELETE',
    data
  })
}

export function removeUser (id) {
  return request({
    url: `/users/${id}`,
    method: 'DELETE'
  })
}

/**** 操作日志 ****/
// 获取用户
export function getLogs (params) {
  return request({
    url: '/operate/log',
    params
  })
}